import request from '@/utils/request'
/**
 *
 * @param {*} param0 (username:用户名, password：密码, repassword，确认密码)
 * @returns
 */
export const registerAPI = ({ username, password, repassword }) => {
  return request({
    url: '/api/reg',
    method: 'POST',
    data: {
      username,
      password,
      repassword
    }
  })
}
/**
 *
 * @param {*} param0 (username:用户名 password:登录密码)
 * @returns Promise对象
 */
export const loginAPI = ({ username, password }) => {
  return request({
    url: '/api/login',
    method: 'POST',
    data: {
      username,
      password
    }
  })
}
/**
 * 获取用户信息
 * @returns promise对象
 */
export const getUserInfoAPI = () => {
  return request({
    url: '/my/userinfo'

  })
}

/**
 * 获取侧边栏数据
 * @returns promise对象
 */
export const getMenusListAPI = () => {
  return request({
    url: '/my/menus'

  })
}
/**
 *
 * @param {*} param0 { id, username, nickname, user_pic }
 * @returns promise对象
 */
export const updateUserInfoAPI = ({ id, email, username, nickname, user_pic }) => {
  return request({
    url: '/my/userinfo',
    method: 'PUT',
    data: {
      id,
      email,
      username,
      nickname,
      user_pic
    }
  })
}

/**
 *
 * @param {*} avatar 头像base64字符串
 * @returns promise对象
 */
export const updateuserAvatarAPI = (avatar) => {
  return request({
    url: '/my/update/avatar',
    method: 'PATCH',
    data: {
      avatar // 头像base64
    }
  })
}

export const updatauserPwdAPI = ({ old_pwd, new_pwd, re_pwd }) => {
  return request({
    url: '/my/updatepwd',
    method: 'PATCH',
    data: {
      old_pwd,
      new_pwd,
      re_pwd
    }
  })
}

/**
 * 获取文章分类
 * @returns
 */
export const getArtCateListApi = () => {
  return request({
    url: '/my/cate/list'
  })
}

/**
 * 新增文章分类
 * @param {*} param0
 * @returns
 */
export const saveArtCateAPI = ({ cate_name, cate_alias }) => {
  return request({
    url: '/my/cate/add',
    method: 'POST',
    data: {
      cate_name,
      cate_alias
    }
  })
}

export const updateArtCateAPI = ({ id, cate_name, cate_alias }) => {
  return request({
    url: '/my/cate/info',
    method: 'PUT',
    data: {
      id,
      cate_name,
      cate_alias
    }
  })
}
